home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / src / java / awt / window~1.jav < prev   
Encoding:
Text File  |  1996-01-12  |  3.8 KB  |  151 lines

  1. /*
  2.  * @(#)Window.java    1.16 95/12/20 Arthur van Hoff
  3.  *
  4.  * Copyright (c) 1995 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19. package java.awt;
  20.  
  21. import java.awt.peer.WindowPeer;
  22.  
  23. /**
  24.  * A Window is a top-level window with no borders and no
  25.  * menubar. It could be used to implement a pop-up menu.
  26.  * The default layout for a window is BorderLayout.
  27.  *
  28.  * @version     1.16, 12/20/95
  29.  * @author     Sami Shaio
  30.  * @author     Arthur van Hoff
  31.  */
  32. public class Window extends Container {
  33.     String      warningString;
  34.  
  35.     Window() {
  36.     SecurityManager sm = System.getSecurityManager();
  37.     if ((sm != null) && !sm.checkTopLevelWindow(this)) {
  38.         warningString = System.getProperty("awt.appletWarning",
  39.                            "Warning: Applet Window");
  40.     }
  41.     }
  42.  
  43.     /**
  44.      * Constructs a new Window initialized to an invisible state. It
  45.      * behaves as a modal dialog in that it will block input to other
  46.      * windows when shown.
  47.      *
  48.      * @param parent the owner of the dialog
  49.      * @see Component#resize
  50.      * @see #show
  51.      */
  52.     public Window(Frame parent) {
  53.     SecurityManager sm = System.getSecurityManager();
  54.  
  55.     if ((sm != null) && !sm.checkTopLevelWindow(this)) {
  56.         warningString = System.getProperty("awt.appletWarning",
  57.                            "Warning: Applet Window");
  58.     }
  59.     this.parent = parent;
  60.     visible = false;
  61.     setLayout(new BorderLayout());
  62.     }
  63.  
  64.     /**
  65.      * Creates the Window's peer.  The peer allows us to modify the appearance of the
  66.      * Window without changing its functionality.
  67.      */
  68.     public synchronized void addNotify() {
  69.     if (peer == null) {
  70.         peer = getToolkit().createWindow(this);
  71.     }
  72.     super.addNotify();
  73.     }
  74.  
  75.     /**
  76.      * Packs the components of the Window.
  77.      */
  78.     public synchronized void pack() {
  79.     if (peer == null) {
  80.         addNotify();
  81.     }
  82.     resize(preferredSize());
  83.     validate();
  84.     }
  85.  
  86.     /**
  87.      * Shows the Window. This will bring the window to the
  88.      * front if the window is already visible.
  89.      * @see Component#hide
  90.      */
  91.     public synchronized void show() {
  92.     if (peer == null) {
  93.         addNotify();
  94.     }
  95.     validate();
  96.  
  97.     if (visible) {
  98.         toFront();
  99.     } else {
  100.         super.show();
  101.     }
  102.     }
  103.  
  104.     /**
  105.      * Disposes of the Window. This method must
  106.      * be called to release the resources that
  107.      * are used for the window.
  108.      */
  109.     public synchronized void dispose() {
  110.     hide();
  111.     removeNotify();
  112.     }
  113.  
  114.     /**
  115.      * Brings the frame to the front of the Window.
  116.      */
  117.     public void toFront() {
  118.     WindowPeer peer = (WindowPeer)this.peer;
  119.     if (peer != null) {
  120.         peer.toFront();
  121.     }
  122.     }
  123.  
  124.     /**
  125.      * Sends the frame to the back of the Window.
  126.      */
  127.     public void toBack() {
  128.     WindowPeer peer = (WindowPeer)this.peer;
  129.     if (peer != null) {
  130.         peer.toBack();
  131.     }
  132.     }
  133.  
  134.     /**
  135.      * Returns the toolkit of this frame.
  136.      * @see Toolkit
  137.      */
  138.     public Toolkit getToolkit() {
  139.     return Toolkit.getDefaultToolkit();
  140.     }
  141.  
  142.     /**
  143.      * Gets the warning string for this window. This is
  144.      * a string that will be displayed somewhere in the
  145.      * visible area of windows that are not secure.
  146.      */
  147.     public final String getWarningString() {
  148.     return warningString;
  149.     }
  150. }
  151.